package com.itheima.mapper;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpExpr;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.Result;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

//select e.*, d.name from emp as e left join dept as d on e.dept_id = d.id
@Mapper
public interface EmpMapper {

    /**
     * 查询总记录数
     */
    /*@Select("select count(*) from emp e left join dept d on e.dept_id = d.id ")
     Long count();*/

    /**
     * 查询所有的员工及其对应的部门名称
     */
    /*@Select("select e.*, d.name deptName from emp as e left join dept as d on e.dept_id = d.id limit #{start}, #{pageSize}")
     List<Emp> list(Integer start , Integer pageSize);

    /**
     * 查询所有的员工及其对应的部门名称
     */


    List<Emp> list(EmpQueryParam queryParam);

    /**
     * 插入员工数据
     */
    @Options(useGeneratedKeys = true,keyProperty = "id") //需要获取数据库自动增长的主键，并赋值给emp对象的id属性
    @Insert("insert into emp (username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) values " +
            "(#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);


    void deleteByIds(List<Integer> ids);

    Emp getById(Integer id);

    void update(Emp emp);
    @MapKey("pos")
    List<Map> getJobData();

    @Select("select * from emp")
    List<Emp> selectAll();
    /**
     * 统计员工性别信息
     */
    @MapKey("name")
    List<Map> countEmpGenderData();
    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp getUserAndPassword(Emp emp);
}
